﻿<MyControl:SelectableItemControl x:Class="UmlControlLibrary.DraggableLabel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:MyControl="clr-namespace:UmlControlLibrary"
    x:Name="UmlControlLibraryDraggableLabel_xaml" MinWidth="30">
    <MyControl:SelectableItemControl.Resources>
        <ControlTemplate x:Key="EditableLabel" TargetType="{x:Type Label}">
            <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" LostFocus="textBox_LostFocus" >
                <Grid.Style>
                    <Style TargetType="Grid">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=UmlControlLibraryDraggableLabel_xaml, Path=Multiline}" Value="False">
                                <Setter Property="Height" Value="23" />                                
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>               
                <Rectangle Name="SelectedDecorator" Visibility="Hidden" Stroke="Black" Fill="#F0F0F0" StrokeThickness="0.5" ></Rectangle>
                <!--ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"-->
                    <TextBlock Name="label" Text="{Binding Content}" FontStyle="{Binding FontStyle}" MouseDown="label_MouseDoubleClick" Margin="5 3 5 0">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=UmlControlLibraryDraggableLabel_xaml, Path=Multiline}" Value="True">
                                        <Setter Property="TextWrapping" Value="WrapWithOverflow" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                <!--/ScrollViewer-->
                <TextBox Name="textBox" Text="{Binding Content, Mode=TwoWay}" FontStyle="{Binding FontStyle}" LostFocus="textBox_LostFocus" KeyDown="textBox_KeyDown" Visibility="Collapsed">
                    <TextBox.Style>
                        <Style TargetType="TextBox">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=UmlControlLibraryDraggableLabel_xaml, Path=Multiline}" Value="True">
                                    <Setter Property="AcceptsReturn" Value="True" />
                                    <Setter Property="AcceptsTab" Value="True" />
                                    <Setter Property="TextWrapping" Value="WrapWithOverflow" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>
            </Grid>
        </ControlTemplate>
    </MyControl:SelectableItemControl.Resources>
    <Grid Width="Auto" Height="Auto">
        <Label Name="Caption" Content="{Binding ElementName=UmlControlLibraryDraggableLabel_xaml, Path=Text, Mode=TwoWay}" Template="{StaticResource EditableLabel}" SourceUpdated="textBox_SourceUpdated" />
    </Grid>
</MyControl:SelectableItemControl>
